//
//  TabBarItem.swift
//  BasicTools
//
//  Created by ikang on 2025/8/20.
//

import SwiftUI

struct TabBarItem: View {
    @Environment(TabGridModel.self) var gridModel
    @Bindable var itemModel: ItemModel
    var currentIndex: Int = 0
    
    var body: some View {
        VStack(spacing: gridModel.space) {
            if !itemModel.normalImage.isEmpty {
                if gridModel.itemType == .image {
                    Image(gridModel.selectIndex == currentIndex ? itemModel.selectImage : itemModel.normalImage)
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: gridModel.imageSize.width, height: gridModel.imageSize.height)
                }else if gridModel.itemType == .system {
                    Image(systemName: itemModel.normalImage)
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: gridModel.imageSize.width, height: gridModel.imageSize.height)
                        .foregroundStyle(gridModel.selectIndex == currentIndex ? gridModel.selectTitleColor : gridModel.normalTitleColor)
                }else if gridModel.itemType == .lottie {
                    
                }
            }
            
            if !itemModel.title.isEmpty {
                Text(itemModel.title)
                    .font(gridModel.titleFont)
                    .foregroundStyle(gridModel.selectIndex == currentIndex ? gridModel.selectTitleColor : gridModel.normalTitleColor)
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .contentShape(Rectangle())
        .onTapGesture {
            gridModel.selectIndex = currentIndex
        }
    }
}

//#Preview {
//    TabBarItem()
//}
